package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ASM_fExpenseDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;
	
	
	public ASM_fExpenseDS(Context context) 
	{
		this.context = context;
		dbHelper  = new ASM_DB(context);
		
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_fExpense det) 
	{
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		
		ContentValues values = new ContentValues();
		
		values.put(ASM_DB.asmFexpen_ExpCode, det.getAsmFexpen_ExpCode());
		values.put(ASM_DB.asmFexpen_ExpName, det.getAsmFexpen_ExpName());
		values.put(ASM_DB.asmFexpen_ExpGrpCode,det.getAsmFexpen_ExpGrpCode());
		values.put(ASM_DB.asmFexpen_Status, det.getAsmFexpen_Status());
		values.put(ASM_DB.asmFexpen_AddUser, det.getAsmFexpen_AddUser());
		values.put(ASM_DB.asmFexpen_AddDate,det.getAsmFexpen_AddDate());
		values.put(ASM_DB.asmFexpen_AddMach, det.getAsmFexpen_AddMach());
		values.put(ASM_DB.asmFexpen_RecordId,det.getAsmFexpen_RecordId());
	


		
		count = (int) dB.insert(ASM_DB.ASM_FEXPENCES, null, values);

		dB.close();
		return count;
		
	}
	
	
	
	public ArrayList<String> getExpense() 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		ArrayList<String> Details = new ArrayList<String>();
	
		String selectQuery = "select ExpName,ExpCode from fExpense where expgrpcode='GAM001' ";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
		
			
			Details.add(cursor.getString(0)+"-:-"+cursor.getString(1));
			
			
			
		}
		
		return Details;
	}
}
